DevForce Help Reference
CreateEntity<T>() Method
Example 


Entity type
Create a new entity of the requested type.
Syntax
'Declaration
 
Public Overloads Function CreateEntity(Of T As Class)() As T
'Usage
 
Dim instance As EntityManager
Dim value As T
 
value = instance.CreateEntity(Of T)()
public T CreateEntity<T>()
where T: class

Type Parameters

T
Entity type

Return Value

A new instance of the specified entity type
Remarks
You may either "new" a business object (unless it's Abstract (or MustInherit in Visual Basic), or use one of the overloaded CreateEntity methods. Any new entity has a "detached" EntityState until added to the EntityManager cache using either AddEntity or the object's EntityAspect.AddToManager method.
Example
DomainModelEntityManager mgr = new DomainModelEntityManager();

// Retrieve an order
Order order = mgr.Orders.FirstOrNullEntity(o=> o.OrderID == 1);
// Retrieve a product
Product product = mgr.Products.FirstOrNullEntity(p => p.ProductID == 1);

// Create an OrderDetail 
OrderDetail dtl = mgr.CreateEntity<OrderDetail>();
// assign key fields
dtl.OrderSummary = order;
dtl.Product = product;

// add the OrderDetail to the EntityManager cache
DebugFns.WriteLine("entity state before add = " + dtl.EntityState);
dtl.AddToManager();
DebugFns.WriteLine("entity state after add = " + dtl.EntityState);
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

EntityManager Class
EntityManager Members
Overload List
AddEntity Method

Send Feedback